package com.njit.WeStudy.dao;
import org.apache.ibatis.jdbc.SQL;

public class UpdateBuilder {
    public String update(String info ,String str,int id){
        return new SQL(){
            {
                UPDATE("user");
                SET(info+"='"+str+"'");
                WHERE("user_id ="+id);
            }
        }.toString();
    }
    //用于更新帖子的点赞、收藏、评论数量
    public String updateInvitationNum(String info,int  num,int id){
        return new SQL(){
            {
                UPDATE("invitation");
                SET(info+"="+num);
                WHERE("invitation_id ="+id);
            }
        }.toString();
    }

    public String updateLikeStatusByUserIdAndInvitationId(int invitationId,boolean status,int userId){
        return new SQL(){
            {
                UPDATE("`like`");
                SET("is_liked = "+status);
                WHERE("invitation_id ="+invitationId+" and user_id="+userId);
            }
        }.toString();
    }

    //用户对帖子(其它用户)的收藏(关注)
    public String updateStarStatusByUserIdAndTargetId(int targetId,String targetType,boolean status,int userId){
        return new SQL(){
            {
                UPDATE("`star`");
                SET("is_stared = "+status);
                WHERE("target_id ="+targetId+" and user_id="+userId+" and target_type= '"+targetType+"'");
            }
        }.toString();
    }

    //更新用户对跟帖(其它用户)的support
    public String updateSupportStatusByUserIdAndTargetId(int targetId,String targetType,boolean status,int userId){
        return new SQL(){
            {
                UPDATE("`support`");
                SET("is_supported = "+status);
                WHERE("target_id ="+targetId+" and user_id="+userId+" and target_type= '"+targetType+"'");
            }
        }.toString();
    }
    //更新storey
    public String updateNumById(String numType, int num, int storeyId){
        return new SQL(){
            {
                UPDATE("`storey`");
                SET(numType+" = "+num);
                WHERE("storey_id ="+storeyId);
            }
        }.toString();
    }
    //更新comment的support_number
    public String updateSupportNumberById(int supportNumber, int commentId){
        return new SQL(){
            {
                UPDATE("`comment`");
                SET("support_number = "+supportNumber);
                WHERE("id ="+commentId);
            }
        }.toString();
    }
}
